<template>
	<view>
		<view class="pake" v-for="(item,key) in pakelist" :key="key" @click="buy(item.id,item.ka)">
			<view class="zi1">
				Package {{item.hours}}{{$t('buywifi.hours')}}
			</view>
			<view class="zi2">
				{{item.ka}}{{$t('test.kips')}}/{{$t('buywifi.qixian')}}{{item.day}}{{$t('buywifi.day')}}
			</view>
			<view class="zi3">
				{{$t('buywifi.goumai')}}
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getResponseData,
		showToastTip,
		getBaseUrl,
		getWsUrl
	} from "@/api/req.js";
	export default {
		data() {
			return {
				type: "warning",
				pakelist: [
					// {
					// 	"id": 1,
					// 	"wifiname": "Package 5小时",
					// 	"desc": "点击购买或凭短信输入net50发送至1131",
					// 	"money": "5000基普/为期一天"
					// },
					// {
					// 	"id": 2,
					// 	"wifiname": "Package10小时",
					// 	"desc": "点击购买或凭短信输入net100发送至1131",
					// 	"money": "10,000基普/为期30天"
					// },
					// {
					// 	"id": 3,
					// 	"wifiname": "Package 50小时",
					// 	"desc": "点击购买或凭短信输入net10发送至1131",
					// 	"money": "50,000基普/为期50天"
					// }
				]
			}
		},
		onLoad() {
			this.getwifi();
		},
		onReachBottom() {
			console.log("上拉加载更多")
			this.pageIndex++;
			this.getwifi();
			//模拟数据请求
			// setTimeout(() => {
			// 		this.cardlist.push(...this.cardlist,...this.cardlist);
			// }, 2000)
		},
		methods: {
			getwifi() {
				var that = this;
				// 得到用户数据
				getResponseData("/wifiCombo/queryWiFiComboByPage", 'get', {
					limit: 10,
					page: this.pageIndex
				}, function(res) {
					console.log(res.data);
					if (res.code == 200) {
						that.pakelist.push(...res.data);
						// console.log(that.cardlist);
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						})
					}
				});
			},
			buy: function(d, ka) {
				uni.showModal({
					title: this.$t('buywifi.buy'),
					content: this.$t('buywifi.qdbuy') + ka + '？',
					confirmText: this.$t('app.qd'),
					cancelText: this.$t('app.qx'),
					success: function(res) {
						if (res.confirm) {
							// 执行确认后的操作
							getResponseData("/wifiCombo/buyWiFiCombo", 'get', {
								id: d
							}, function(res) {
								// console.log(res.data);
								if (res.code == 200) {
									uni.showToast({
										title: res.msg,
										icon: 'none',
										duration: 2000
									})
								}

							});

						} else {
							// 执行取消后的操作
						}
					}
				})
			}

		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #F0F0F0;
	}

	.pake {
		width: 90%;
		margin: auto;
		// border: 1px #1eb9ee solid;
		background-color: #1eb9ee;
		border-radius: 5px;
		margin-top: 20px;
		color: white;
		text-align: center;

	}

	.pake>view {
		line-height: 30px;
	}

	.zi1 {
		font-size: 18px;
		font-weight: 600;
	}

	.zi2 {
		font-size: 14px;
	}

	.zi3 {
		font-size: 16px;
	}
</style>